package com.chey.service.impl;

import com.chey.dao.CklsDao;
import com.chey.pojo.META;
import com.chey.pojo.ckls.CKLS;
import com.chey.pojo.ckls.CNTR;
import com.chey.pojo.ckls.DFLT;
import com.chey.pojo.ckls.MSG11;
import com.chey.service.CklsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * @author JanYao
 * @version 0.1
 */
@Service
public class CklsServiceImpl implements CklsService {
    @Autowired
    private CklsDao cklsDao;

    @Override
    public Integer insert(MSG11 msg) {

        String ckls_uuid = UUID.randomUUID().toString().replace("-", "").toLowerCase();

        cklsDao.addMeta(ckls_uuid, msg.getMeta());

        cklsDao.addCkls(ckls_uuid, msg.getDflt(), msg.getDflt().getCkls());

        if (msg.getDflt().getCkls().getCNTR() == null) {
            return null;
        }
        for (CNTR cntr : msg.getDflt().getCkls().getCNTR()) {

            cklsDao.addCntr(ckls_uuid, cntr);
        }
        return null;
    }
}
